import { listDepreacitionRules } from '@/apis/asset/common'
import { ref } from 'vue'

/** 折旧规则模块 */
export function depreacitionRules(options?: { onSuccess?: () => void }) {

    const loading = ref(false)
    const depreacitionRulesList = ref([{}])

    const getDepreacitionRules = async (name?: string) => {
        try {
            loading.value = true
            const res = await listDepreacitionRules({ name: name })
            const data = res.data;
            depreacitionRulesList.value = data.map(item => {
                return {
                    label: item.name,
                    value: item.id
                };
            });
            options?.onSuccess && options.onSuccess()
        }finally {
            loading.value = false
        }
    }
    return { depreacitionRulesList, getDepreacitionRules, loading }
}

